
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Iterator;
import java.util.LinkedList;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 * This class is SpecialAdd
 */
public class SpecialAdd extends JPanel{
	/**
	 * SpecialAdd variables
	 */
	private JPanel curPanel;
	private JLabel lbltitle;
	public JButton btnBack;
	public JButton btnHelp;
	private JComboBox mngBox = null;
	private JButton btnSelect = null;
	private JLabel lblEx;
	private LinkedList<SException> msg;


	/**
	 * This is the default SpecialAdd constructor
	 */
	public SpecialAdd() {
		super();
		System.out.println("now in SpecialAdd with NO exception constractor");
		EmptyInitialize();
	}
	/**
	 * This method initializes EmptyInitialize
	 */
	private void EmptyInitialize() {
		curPanel = this;

		this.setVisible(true);
		this.setVisible(true);

		lbltitle = new JLabel("Manager window");
		lbltitle.setBounds(187, 28, 110, 14);

		this.setSize(400, 321);
		this.setLayout(null);
		
		this.add(lbltitle);
		
		lblEx = new JLabel("There are no Exceptions here");
		lblEx.setBounds(125, 67, 180, 14);
		this.add(lblEx);
		/**
		 *  Back button Implementation
		 */
		btnBack = new JButton("Back");
		btnBack.setBounds(187, 253, 86, 25);
		this.add(btnBack,null);
		this.setVisible(true);
		btnHelp = new JButton("Help");
		btnHelp.setBounds(390, 11, 80, 19);
		btnHelp.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				  HelpWin help = new HelpWin ("Click on one of the option");
				  System.out.println("user press Help button");
			}
		});
		this.add(btnHelp,null);
	}
	/**
	 * This method initializes SpecialAdd
	 * @param msg
	 */
	public SpecialAdd(Object msg) {
		super();
		System.out.println("now in SpecialAdd with exception constractor");
		this.msg = (LinkedList<SException>) msg;
		initialize();
	}
	/**
	 * This method initializes SpecialRemove
	 */
	private void initialize() {
		curPanel = this;

		this.setVisible(true);
		this.setVisible(true);

		lbltitle = new JLabel("Manager window");
		lbltitle.setBounds(187, 28, 110, 14);

		this.setSize(400, 321);
		this.setLayout(null);
		
		this.add(lbltitle);
		
		btnSelect = new JButton();
		btnSelect.setBounds(new Rectangle(187, 204, 95, 19));
		btnSelect.setText("Select");
		this.add(btnSelect(),null);
		
		lblEx = new JLabel("Choose an exception to see");
		lblEx.setBounds(125, 67, 180, 14);
		this.add(lblEx);
		/**
		 *  Back button Implementation
		 */
		btnBack = new JButton("Back");
		btnBack.setBounds(187, 253, 86, 25);
		this.add(btnBack,null);
		this.setVisible(true);
		
		this.add(getMngBox(),null);
		btnSelect = new JButton();
		btnSelect.setBounds(new Rectangle(141, 172, 95, 19));
		btnSelect.setText("Select");
		/**
		 *  Help button Implementation
		 */
		btnHelp = new JButton("Help");
		btnHelp.setBounds(390, 11, 80, 19);
		btnHelp.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				  HelpWin help = new HelpWin ("Click on one of the option");
				  System.out.println("user press Help button");
			}
		});
		this.add(btnHelp,null);

	}
	
	/**
	 * This method initializes getMngBox
	 * @return	getMngBox
	 */
	private JComboBox getMngBox() {
		if (mngBox == null) {
			mngBox = new JComboBox();
			mngBox.setBounds(new Rectangle(176, 94, 95, 17));
			
			Iterator<SException> itr = msg.iterator();
			while (itr.hasNext())
				mngBox.addItem(itr.next().getExceptionID());
			
			mngBox.addItemListener(new java.awt.event.ItemListener() {
				public void itemStateChanged(java.awt.event.ItemEvent e) {
					System.out.println("itemStateChanged()"); 
				}
			});
		}
		return mngBox;
	}
	/**
	 * This method initializes btnSelect
	 * @return	btnSelect
	 */
	private JButton btnSelect() {
		this.btnSelect.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				System.out.println("this is what in the box "+mngBox.getSelectedItem());
				Object ID = mngBox.getSelectedItem().toString();
				Iterator<SException> itr = msg.iterator();
				boolean flag=true;
				SException EX = new SException();
				while (itr.hasNext()&&flag)
				{
					EX = itr.next();
					if (EX.getExceptionID().equals(ID)) 
						flag = false;
				}
				SQL s = new SQL(EX,32);
				s.accept();
				//System.out.println("TEMP MSG   " + Global.chat.temp);
				Object msg = s.getMsg();
				System.out.println(msg.toString());
				
			}
		});
		return btnSelect;
	}
	
}
